<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class LinkController extends Controller
{
    public function add()
    {
    return view('/admin/link/add',['title' => '友情链接']);
	}

	public function insert(Request $request){
		$data = $request->except('_token');
		$res = DB::table('admin_link')->insert($data);
		if($res){
			return  redirect('/admin/link/index') -> with(['info' => '添加成功']);
		}else{
			return back() -> with(['info' => '添加失败']);
    		}
	}

	//友情链接列表
    public function index(){
       
    	$date = DB::table('admin_link') -> get();
        //dd($data);
        	return  view('/admin/link/index',['date'=>$date]);
    }

    public function edit($a_lid){
    	$data = DB::table('admin_link')->where('a_lid',$a_lid)->first();
    	return view('/admin/link/edit',['data'=>$data]);
    }

    public function updata(Request $request){
    	$data = $request->except('_token');
    	
    	$res = DB::table('admin_link') -> where('a_lid',$data['a_lid']) ->update($data);
    	
    	if($res)
    	{
    		return redirect('/admin/link/index') -> with(['info' => '修改成功']);
    	}else
    	{
    		return back() -> with(['info' => '修改失败']);
    	}
    }
    public function delete($a_lid){
    	$res = DB::table('admin_link')->where('a_lid',$a_lid)->delete();
    	if($res)
    	{
    		return redirect('/admin/link/index') -> with(['info' => '删除成功']);
    	}else
    	{
    		return back() -> with(['info' => '删除失败']);
    	}
    }

    public function up($a_lid){
    		$res = DB::table('admin_link')->where('a_lid',$a_lid)->update(['a_lstatus'=>2]);
    		if($res)
    		{
	    		return redirect('/admin/link/index') -> with(['info' => '上线成功']);
	    	}else
	    	{
	    		return back() -> with(['info' => '上线失败']);
	    	}
    }

    public function down($a_lid){
    		$res = DB::table('admin_link')->where('a_lid',$a_lid)->update(['a_lstatus'=>1]);
    		if($res)
    		{
	    		return redirect('/admin/link/index') -> with(['info' => '下线成功']);
	    	}else
	    	{
	    		return back() -> with(['info' => '下线失败']);
	    	}
    }
}
